package com.itheima.shop.strategy;

import org.springframework.beans.BeansException;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: design
 * @description:
 * @author: zhanghz001
 * @create: 2020-12-15 14:04
 **/
@Component("strategyFacotry")
@ConfigurationProperties(prefix = "strategy")
public class StrategyFactory implements ApplicationContextAware {
    private Map<Integer, StPayFactoryring> strategyMap = new HashMap<>();
    
    private ApplicationContext applicationContext;
    
    public VipMoney get(Integer level) {
        String beanName = strategyMap.get(level);
        VipMoney vipMoney = applicationContext.getBean(beanName, VipMoney.class);
        return vipMoney;
    }
    
    public void setStrategyMap(Map<Integer, String> strategyMap) {
        this.strategyMap = strategyMap;
    }
    
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
        
    }
}
